<?php
// +----------------------------------------------------------------------
// | 鸿运集团 [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------


namespace app\admin\controller;

use \think\Db;
use \think\Cookie;
use app\admin\controller\Permissions;
class Main extends Permissions
{
    public function index()
    {
        /**
         *交易数据
         */
		$time = input('tptime') ? input('tptime') : 'today';  
		$this->assign('time',$time);
		
		//查询出新增会员数量
		$ucount = db('user')->whereTime('add_time',$time)->count();
		$this->assign('ucount',$ucount);
		//查询出房券赠送总数
		$info['zs'] = db('consume')->where('type',3)->whereTime('time',$time)->field('sum(num) as num,count(id) as count')->select();
		
		$where1['state'] = 2;
		//会员卡充值金额 
		$info['cz'] = db('paylog')->where('type',2)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//会员购卡金额 
		$info['gk'] = db('paylog')->where('type',1)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//会员卡消费金额 
		$where2['type'] = ['in',[3,8,9]];
		$info['xf'] = db('paylog')->where($where2)->where('pay_type',5)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//查询出订单总金额，实收总金额 
		$where3['type'] = ['not in',[4,7]];
		$info['total'] = db('paylog')->where($where3)->where('pay_type','neq',6)->where('state',2)->whereTime('add_time',$time)->field('sum(balance)-sum(tk_money) as je,count(id) as bs,sum(origin_price)-sum(tk_money) as price')->select();
		 
		//房券核销总数  
		$info['hx'] = db('paylog')->where('type',5)->where($where1)->whereTime('add_time',$time)->field('sum(hx_total) as je,count(id) as bs')->select();
		
		//微信  
		$info['wx'] = db('paylog')->where('pay_type',2)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//支付宝  
		$info['zfb'] = db('paylog')->where('pay_type',3)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//银联 
		$info['yhk'] = db('paylog')->where('pay_type',8)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//现金 
		$info['xj'] = db('paylog')->where('pay_type',1)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		
		//其他 
		$info['qt'] = db('paylog')->where('pay_type',4)->where($where1)->whereTime('add_time',$time)->field('sum(balance) as je,count(id) as bs')->select();
		$this->assign('info',$info);  

        return $this->fetch();
    }
}
